﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using HySoft.Cash.BaseClass;
using System.Configuration;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using Huayou.Utils;
using HySoft.Cash;
using System.Web.UI.HtmlControls;
using PayRoller.Code;

namespace PayRoller.Include
{
    /// <summary>
    /// 由于本控件将会被企业和后台管理员同时使用，而不同人使用的时候，传递OrgID的方式不同。
    /// </summary>
    public partial class UEmpDetails : System.Web.UI.UserControl
    {
        public string Address1 = "";
        public string Address2 = "";
        public DataTable dtBankPayment = new DataTable();
        public string EmpName = "";
        protected Label lblTip;
        public string NetPayment = "";
        public string NextPayday = "";
        public string OrgEmpSid = "";
        public string PayFrequency = "";
        public string PayStartDate = "";
        public string Sid = "";
        public string sNetPayment = "0.00";
        public string TaxFileNumber = "";
        public string OrgSid = "";
        //public HtmlAnchor aEmployeeList;

        // Methods
        //public DataTable GetBankPayment(int EmpSid)
        //{
        //    //int invoiceOverDueDays= AppSettings.InvoiceOverDueDays;
        //    SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@EmpSid", EmpSid), new SqlParameter("@InvoiceOverDueDate", SafeDateTime.LocalToday) };
        //    return SqlHelper.ExecuteDataset(ConfigurationManager.AppSettings["SQLConnString"], CommandType.StoredProcedure, "GetBankPayment", commandParameters).Tables[0];
        //}

        public string GetSumPaymentByEmp(int EmpSid)
        {
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@EmpSid", EmpSid) };
            DataTable table = SqlHelper.ExecuteDataset(ConfigurationManager.AppSettings["SQLConnString"], CommandType.StoredProcedure, "GetSumPaymentByEmp", commandParameters).Tables[0];
            if ((table.Rows.Count > 0) && (((table.Rows[0][0].ToString() != null) && (table.Rows[0][0].ToString() != "&nbsp;")) && (table.Rows[0][0].ToString() != "")))
            {
                return table.Rows[0][0].ToString();
            }
            return "0.00";
        }


        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            LoadInfo();
        }

        private void LoadInfo()
        {
            if (base.Request["Sid"] != null)
            {
                try
                {
                    int sid = Convert.ToInt32(base.Request["Sid"].ToString());
                    TempinfoBN obn = new TempinfoBN(this.Page);
                    TempinfoDT odt = obn.Get(sid);
                    this.Sid = odt.Sid.ToString();
                    this.OrgSid = odt.OrgSid.ToString();
                    this.OrgEmpSid = odt.OrgEmpSid;
                    this.EmpName = odt.EmpName;
                    this.TaxFileNumber = odt.TaxFileNumber;
                    this.PayStartDate = DateUtils.DateFormatWithCulture(odt.PayStartDate, AppSettings.CurrentCulture);
                    this.PayFrequency = odt.PayFrequency;
                    this.NextPayday = DateUtils.DateFormatWithCulture(odt.NextPayday, AppSettings.CurrentCulture);
                    this.NetPayment = odt.NetPayment.ToString();
                    this.Address1 = odt.Address1;
                    this.Address2 = odt.Address2;
                    obn.Dispose();
                    obn = null;
                    this.sNetPayment = this.GetSumPaymentByEmp(sid);
                    this.dtBankPayment = Misc.GetBankPayment(sid);
                }
                catch (Exception exception)
                {
                    this.lblTip.Text = exception.Message;
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.isAdminUse == true)
            {
                this.aEmployeeList.HRef = "~/Manage/OrgInfo/EmpList.aspx?OrgSid=" + this.OrgSid;
            }
            else
            {
                this.aEmployeeList.HRef = "~/Member/EmpList.aspx";
            }
        }


        private bool isAdminUse = false;
        public bool IsAdminUse
        {
            get { return this.isAdminUse; }
            set { this.isAdminUse = value; }
        }
    }
}